<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.util.List" %>
<%@ page import="javax.jdo.PersistenceManager" %>
<%@ page import="com.google.appengine.api.users.User" %>
<%@ page import="com.google.appengine.api.users.UserService" %>
<%@ page import="com.google.appengine.api.users.UserServiceFactory" %>
<%@ page import="com.brooklynmarathon.checkout.Customer" %>
<%@ page import="com.brooklynmarathon.checkout.Notify" %>
<%@ page import="com.brooklynmarathon.checkout.PMF" %>

<html>
  <head>
    <link type="text/css" rel="stylesheet" href="/stylesheets/main.css" />
  </head>

  <body>

<%
try
{
    UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();
    if (user != null) {
%>
<p>Hello, <%= user.getNickname() %>! (You can
<a href="<%= userService.createLogoutURL(request.getRequestURI()) %>">sign out</a>.)</p>
<%
    } else {
%>
<p>Hello!
<a href="<%= userService.createLoginURL(request.getRequestURI()) %>">Sign in</a>
to include your name with Notifys you post.</p>
<%
    }
%>

<%
    PersistenceManager pm = PMF.get().getPersistenceManager();
    String query = "select from " + Notify.class.getName() + " order by created desc range 0,10";
    List<Notify> Notifys = (List<Notify>) pm.newQuery(query).execute();
    if (Notifys.isEmpty()) {
%>
<p>no messages.</p>
<%
    } else {
        for (Notify g : Notifys) {
            if (g.getAuthor() == null) {
%>
<p>===anonymous:</p>
<%
            } else {
%>
<p><b>===<%= g.getAuthor().getNickname() %></b>:</p>
<%
            }
%>
<blockquote><b>callerReference: </b><%= g.getCallerReference() %> <br/><b>Data: </b><%= g.getData().getValue() %> <%=g.getCreated()%></blockquote>

<%

    String query1 = "select from " + Customer.class.getName() + " where CallerReference == callerReferenceParameter parameters String callerReferenceParameter";
    List<Customer> Customers = (List<Customer>) pm.newQuery(query1).execute(g.getCallerReference());
    if (Customers.isEmpty()) {
    }
    else
    {
    for (Customer c : Customers) 
    {
    %>
    <p>Customer: <%=c.getAmount()%> , <%=c.getReason()%>
<%
    }
    }
%>


<%
        }
    }
    pm.close();

    }
    catch (Exception e)
    {
    %>
    Error: <%=e.getMessage()%>
    <%
    }
%>


  </body>
</html>
